﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script src="../Scripts/plupload/plupload.full.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=111",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "../system/error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab = tabs.getTab("tab$111");
                    tabs.removeTab(tab);
                }
            }
        });

        var States = [{ id: 0, text: '显示' }, { id: 1, text: '隐藏' }, { id: '', text: '全部'}];
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td>
                    企业：
                    <input class="mini-textbox" id="key" emptytext="关键字" />
                    状态：
                    <input id="state" class="mini-combobox" style="width: 60px;" data="States" value="0" />
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow();">新增</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-unlock" plain="true" onclick="lockRows(0);">显示</a>
                    <a class="mini-button" iconcls="icon-lock" plain="true" onclick="lockRows(1)">隐藏</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit" >
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetVideoList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="50px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="uv_title" headeralign="center" align="center" allowsort="true" renderer="onNameRenderer">
                    企业</div>
                <div field="uv_hits" width="100px" headeralign="center" align="center" allowsort="true">
                    点击数</div>
                <div field="uv_inserttime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    添加时间</div>
                <div field="su_login" width="50px" headeralign="center" align="center" allowsort="true">
                    添加人</div>
                <div field="uv_insertip" width="70px" headeralign="center" align="center" allowsort="true">
                    添加IP</div>
                <div field="uv_modifytime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    最后修改时间</div>
                <div field="modifylogin" width="60px" headeralign="center" align="center" allowsort="true">
                    最后修改人</div>
                <div field="uv_modifyip" width="70px" headeralign="center" align="center" allowsort="true">
                    最后修改IP</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="视频信息" style="width: 550px; height:auto;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <table style="width: 100%; height: 100%;">
                <tr style="height: 20px">
                    <td class="tdtitle" style="width: 60px;">
                        <span class="red">*</span>企业：
                    </td>
                    <td class="tdtext">
                        <input name="uv_title" class="mini-textbox" style="width:300px;" required="true"/>
                    </td>
                </tr>
<!--                <tr style="height: 20px">
                    <td class="tdtitle">
                        图片：
                    </td>
                    <td class="tdtext">
                        <input id="uv_img" name="uv_img" style="width:300px;" class="mini-textbox" enabled="false"/>
                        <a id="img" class="mini-button" iconcls="icon-folderopen" plain="true">选择图片</a>
                        <a id="lookimg" style="display:none;" class="linelink" target="_blank">预览图片</a>
                    </td>
                </tr>-->
                <tr style="height: 20px">
                    <td class="tdtitle">
                        <span class="red">*</span>视频：
                    </td>
                    <td class="tdtext">
                        <input id="uv_video" name="uv_video" style="width:300px;" class="mini-textbox" required="true" enabled="false"/>
                        <a id="file" class="mini-button" iconcls="icon-folderopen" plain="true">选择文件</a>
                    </td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();
        var id;
        var video;
        var img;
        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'file',
            url: "../data/import.aspx?method=ImportVideo&dir=flash",
            filters: {
                max_file_size: '100mb',
                mime_types: [{ title: "视频文件(*.swf;*.flv;*.mp4;*.wav;*.wma;*.wmv;*.mid;*.avi;*.mpg;*.asf;*.rm;*.rmvb)", extensions: "swf,flv,mp4,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"}]
            },
            flash_swf_url: '../Scripts/plupload/Moxie.swf',
            silverlight_xap_url: '../Scripts/plupload/Moxie.xap',
            init: {
                FilesAdded: function (up, files) {
                    uploader.start();
                },
                UploadProgress: function (up, file) {
                    mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '视频上传中，请稍后...' });
                },
                UploadComplete: function (up, file) {
                    mini.unmask(document.body);
                },
                FileUploaded: function (up, file, res) {
                    if (res.response == -1) {
                        ShowMessage("系统提示", "选择的文件中没有数据！", 2);
                    }
                    else if (res.response == -2) {
                        ShowMessage("系统提示", "选择的文件不是视频文件！", 2);
                    }
                    else {
                        video = res.response;
                        mini.get("uv_video").setValue(video);
                    }
                },
                Error: function (up, err) {
                    ShowMessage("系统提示", "视频上传失败！", 3);
                }
            }
        });

//        var uploader2 = new plupload.Uploader({
//            runtimes: 'html5,flash,silverlight,html4',
//            browse_button: 'img',
//            url: "../data/import.aspx?method=ImportVideo&dir=image",
//            filters: {
//                max_file_size: '10mb',
//                mime_types: [{ title: "图片文件(*.gif;*.jpg;*.jpeg;*.png;*.bmp)", extensions: "gif,jpg,jpeg,png,bmp"}]
//            },
//            resize: {width: 320, height: 240, quality: 90},
//            flash_swf_url: '../Scripts/plupload/Moxie.swf',
//            silverlight_xap_url: '../Scripts/plupload/Moxie.xap',
//            init: {
//                FilesAdded: function (up, files) {
//                    uploader2.start();
//                },
//                UploadProgress: function (up, file) {
//                    mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '图片上传中，请稍后...' });
//                },
//                UploadComplete: function (up, file) {
//                    mini.unmask(document.body);
//                },
//                FileUploaded: function (up, file, res) {
//                    if (res.response == -1) {
//                        ShowMessage("系统提示", "选择的文件中没有数据！", 2);
//                    }
//                    else if (res.response == -2) {
//                        ShowMessage("系统提示", "选择的文件不是图片文件！", 2);
//                    }
//                    else {
//                        img = res.response;
//                        mini.get("uv_img").setValue(img);
//                        $("#lookimg").attr("href", img);
//                        $("#lookimg").show();
//                    }
//                },
//                Error: function (up, err) {
//                    ShowMessage("系统提示", "图片上传失败！", 3);
//                }
//            }
//        });

        uploader.init();

        //uploader2.init();

        var grid = mini.get("datagrid1");
        search();

        function search() {
            var key = mini.get("key").getValue();
            var state = mini.get("state").getValue();
            grid.load({ key: key, state: state });
            grid.sortBy("uv_No", "desc");
        }

        function addRow() {
            id = "";
            var form = new mini.Form("#editform");
            form.reset();
            form.loading();
            form.unmask();
            var win = mini.get("editWindow");
            win.setTitle("新增上传视频<span class='red'>( 带 * 号的必须填写)</span>");
            if (!win.visible)
                win.show();
        }

        function editRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                id = row.uv_no;
                var win = mini.get("editWindow");
                var form = new mini.Form("#editform");
                form.clear();
                form.loading();
                $.ajax({
                    url: "../data/system.aspx?method=GetVideo&id=" + row.uv_no,
                    success: function (text) {
                        form.unmask();
                        if (text == "out") {
                            win.hide();
                            var loginWindow = parent.mini.get("loginWindow");
                            if (!loginWindow.visible)
                                loginWindow.show();
                            return;
                        }
                        var o = mini.decode(text);
                        form.setData(o);
                        //img = o.uv_img;
                        video = o.uv_video;
                        win.setTitle("编辑上传视频<span class='red'>( 带 * 号的必须填写)</span>");
                        win.show();
                    },
                    error: function () {
                        form.unmask();
                        ShowMessage("系统提示", "表单加载出错！", 3);
                    }
                });
            }
        }

        function updateRow() {
            var form = new mini.Form("#editform");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var json = mini.encode(o);

            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });
            $.ajax({
                url: "../data/system.aspx?method=SaveVideo",
                data: { id: id, img: img, file: video, data: json },
                type: "post",
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    var editWindow = mini.get("editWindow");
                    if (ret == 1) {
                        editWindow.hide();
                        ShowMessage("系统提示", "视频信息保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        editWindow.hide();
                        ShowMessage("系统提示", "该视频已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else
                        ShowMessage("系统提示", "视频信息保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "视频信息保存失败！", 3);
                }
            });
        }

        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除此视频吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteVideo",
                                type: "post",
                                data: { id: row.uv_no },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定删除所选视频吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].uv_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteVideo",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                ShowMessage("系统提示", "请选择需要删除的视频！", 2);
        }

        function lockRows(state) {
            var rows = grid.getSelecteds();
            var msg = "隐藏";
            if (state == 0)
                msg = "显示";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选视频吗？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].uv_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=LockVideo",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            } else
                ShowMessage("系统提示", "请选择需要" + msg + "的视频！", 2);
        }

        function topRows(state) {
            var rows = grid.getSelecteds();
            var msg = "置顶";
            if (state == 0)
                msg = "取消置顶";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选视频？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].uv_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=TopNews",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的视频！", 2);
        }

        function redRows(state) {
            var rows = grid.getSelecteds();
            var msg = "描红";
            if (state == 0)
                msg = "取消描红";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选视频？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].uv_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=RedNews",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的视频！", 2);
        }

        function newRows(state) {
            var rows = grid.getSelecteds();
            var msg = "设置最新";
            if (state == 0)
                msg = "取消最新";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选视频？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            var messageid = mini.loading("操作中，请稍后......", "系统提示");
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].uv_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=NewNews",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的视频！", 2);
        }

        function refreshRows(state) {
            var rows = grid.getSelecteds();
            var msg = "刷新";
            if (state == 0)
                msg = "取消刷新";
            if (rows.length > 0) {
                mini.confirm("确定" + msg + "所选视频？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '操作中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].uv_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=RefreshNews",
                                type: "post",
                                data: { id: ids, state: state },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "视频" + msg + "成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "视频" + msg + "失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要" + msg + "的视频！", 2);
        }

        function closewin() {
            var win = mini.get("editWindow");
            win.hide();
        }

        function onDelete() {
            $("#img").attr("href", "");
            mini.get("nw_img").setValue("");
            $(".ke-button").val("上传");
            $("#spanload").hide();
        }

        //上传文件数显示
        function onFileRenderer(e) {
            var s = e.value;
            if (e.value != null && e.value > 0)
                s = '<a class="linelink" title="详细" href="javascript:void(0);" onclick="fileRows(' + e.record._uid + ')">查看</a> (' + e.value + ')';
            return s;
        }

        //上传文件管理
        function fileRows(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                var tabs = parent.mini.get("mainTabs");
                var tab = tabs.getTab("tab$107");
                tab.enabled = false;
                showPTab(row.uv_no);
            }
        }

        //打开上传文件管理Tab
        function showPTab(uv_no) {
            var tabs = parent.mini.get("mainTabs");
            var id = "tab$file" + uv_no;
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab.name = id;
                tab.title = "上传文件查看";
                tab.showCloseButton = true;
                tab.url = "news/file.html?method=107&nwno=" + uv_no;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
        }
    </script>
</body>
</html>